<?php


namespace App\Admin\Controllers;


use App\Models\Slideshow;
use Illuminate\Http\Request;
use SmallRuralDog\Admin\Layout\Content;
use SmallRuralDog\Admin\Controllers\AdminController;
use SmallRuralDog\Admin\Controllers\AdminResource;
use SmallRuralDog\Admin\Form;
use SmallRuralDog\Admin\Grid;
use SmallRuralDog\Admin\Components\Form\RadioGroup;
use SmallRuralDog\Admin\Components\Form\Radio;
use SmallRuralDog\Admin\Components\Widgets\Divider;
use SmallRuralDog\Admin\Components\Grid\Avatar;
use SmallRuralDog\Admin\Components\Grid\Tag;
use SmallRuralDog\Admin\Components\Form\CSwitch;
use SmallRuralDog\Admin\Components\Form\Upload;
use SmallRuralDog\Admin\Components\Form\InputNumber;
use SmallRuralDog\Admin\Components\Form\Checkbox;

class SlideshowController extends AdminController
{
    public function grid()
    {
        $grid = new Grid(new Slideshow());
        $grid->column('title', "标题");
        $grid->column('imgurl', "图片")->width(80)->align('center')->component(Avatar::make());
        $grid->column('path', "链接地址");
        $grid->column('is_show', "是否显示")->width(100)->align("center")->customValue(function ($row, $value) {
            return $value == 1 ? "显示" : "不显示";
        })->component(Tag::make()->type(["上架" => "success", "下架" => "danger"]));
        $grid->column('order', "排序");
        $grid->column('status', "位置")->customValue(function ($row, $value) {
            $sex_name = ['0' => '首页', '1' => '其它'];
            return $sex_name[$value];
        })->width(100)->sortable();

        $grid->actions(function (Grid\Actions $actions) {
        });


        $grid->toolbars(function (Grid\Toolbars $toolbars) {
            $toolbars->createButton()->content("添加轮播图");
        });
        return $grid;
    }

    public function form($isEdit = false)
    {
        $form = new Form(new Slideshow());

        $form->labelWidth("250px");
        $form->item('title', "轮播标题")->required()->inputWidth(5);
        $form->item('imgurl', '轮播图片')->required()->component(Upload::make()->width(150)->height(150));
        $form->item('path', "链接地址")->inputWidth(5);
        $form->item('order', '轮播排序')->required()->component(InputNumber::make(1));
        $form->item('status', '轮播位置')->required()->component(RadioGroup::make(0)->options([
            Radio::make(0, "首页"),
            Radio::make(1, "其它"),
        ]));
        $form->item("is_show", "是否显示")->component(RadioGroup::make(1)->options([
            Radio::make(1, "显示"),
            Radio::make(0, "不显示"),
        ]));

        return $form;
    }


}
